package ru.pb.game.data.xml.holders;

import gnu.trove.map.TIntObjectMap;
import gnu.trove.map.hash.TIntObjectHashMap;
import ru.pb.game.data.templates.players.PlayerTemplate;
import ru.pb.global.xml.holder.AbstractHolder;

/**
 * @author Felixx
 */
public final class PlayerTemplateHolder extends AbstractHolder
{
	private static PlayerTemplateHolder _instance;

	private final TIntObjectMap<PlayerTemplate> _templates = new TIntObjectHashMap<PlayerTemplate>();

	public static PlayerTemplateHolder getInstance()
	{
		if(_instance == null)
		{
			_instance = new PlayerTemplateHolder();
		}
		return _instance;
	}

	private PlayerTemplateHolder()
	{}

	public PlayerTemplate getTemplate(int id)
	{
		return _templates.get(id);
	}

	public void addTemplate(PlayerTemplate template)
	{
		_templates.putIfAbsent(template.getId(), template);
	}

	@Override
	public int size()
	{
		/*
		 * for(PlayerTemplate t : _templates.valueCollection())
		 * {
		 * _log.info("template id: " + t.getId());
		 * _log.info("rank: " + t.getRank().name() + "; id=" + t.getRank().get());
		 * _log.info("gp: " + t.getGamePoint());
		 * _log.info("money: " + t.getMoney());
		 * for(int i : t.getStartWeapons().toArray())
		 * {
		 * _log.info("weapons: " + i);
		 * }
		 * for(int i : t.getStartArmors().toArray())
		 * {
		 * _log.info("armors: " + i);
		 * }
		 * for(int i : t.getStartCupons().toArray())
		 * {
		 * _log.info("cupons: " + i);
		 * }
		 * }
		 */

		return _templates.size();
	}

	@Override
	public void clear()
	{
		_templates.clear();
	}
}